package com.guigu.qingcheng.servicegoods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.qingcheng.pojo.goods.TbTemplate;
import com.guigu.qingcheng.servicegoods.mapper.TbTemplateMapper;
import com.guigu.qingcheng.servicegoods.service.TbTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class TbTemplateServiceImpl extends ServiceImpl<TbTemplateMapper, TbTemplate> implements TbTemplateService {
    @Resource
    private TbTemplateMapper mapper;

    @Autowired
    private TbTemplateService tbTemplateService;

    //根据条件查询封装查询对象
    public QueryWrapper<TbTemplate> queryWrapper(Map<String, Object> searchMap){
        QueryWrapper<TbTemplate> wapper = new QueryWrapper<TbTemplate>();
        if(searchMap != null){
            if(searchMap.get("id") != null && !"".equals(searchMap.get("id")))
                wapper.eq("id", searchMap.get("id"));
            if(searchMap.get("name") != null && !"".equals(searchMap.get("name")))
                wapper.eq("name", searchMap.get("name"));
            if(searchMap.get("specNum") != null && !"".equals(searchMap.get("specNum")))
                wapper.eq("spec_num", searchMap.get("specNum"));
            if(searchMap.get("paraNum") != null && !"".equals(searchMap.get("paraNum")))
                wapper.eq("para_num", searchMap.get("paraNum"));
        }
        return wapper;
    }

    @Override
    public Page<TbTemplate> findPage(Map<String, Object> searchMap, int page, int size) {
        Page<TbTemplate> pageTbTemplate = new Page<TbTemplate>(page, size);
        QueryWrapper<TbTemplate> query = queryWrapper(searchMap);
        IPage<TbTemplate> list = this.tbTemplateService.page(pageTbTemplate, query);
        return pageTbTemplate;
    }

    @Override
    public List<TbTemplate> findList(Map<String, Object> searchMap) {
        QueryWrapper<TbTemplate> wrapper = queryWrapper(searchMap);
        List<TbTemplate> list = this.tbTemplateService.list(wrapper);
        return list;
    }
}
